<template>
  <div>
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="名称">
          <el-input v-model="form.name" />
        </el-form-item>
        <el-form-item label="编号">
          <el-input v-model="form.code" />
        </el-form-item>
        <el-form-item label="描述">
          <el-input v-model="form.description" />
        </el-form-item>
        <el-form-item label="开启">
          <el-switch
            v-model="form.enVisible"
            :active-value="1"
            :inactive-value="0"
            active-color="#13ce66"
            inactive-color="#ff4949"
          />
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { addPermission, editPermission } from '@/api/permission'
export default {
  name: 'Add',
  components: {},
  props: {},
  data() {
    return {
      dialogVisible: false,
      form: {
        name: '',
        code: '',
        description: '',
        type: 0,
        pid: 0,
        enVisible: '0' // 0关闭， 1 开启
      }

    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    open(type, pid) {
      this.dialogVisible = true
      this.form.type = type
      this.form.pid = pid
    },
    edit(row) {
      this.dialogVisible = true
      this.form = { ...row }
    },
    async submit() {
      // await addPermission(this.form)
      if (this.form.id) {
        // 编辑
        await editPermission(this.form)
      } else {
        await addPermission(this.form)
      }
      this.dialogVisible = false
      this.$message.success('添加成功')
      this.$emit('refresh')
    }

  }
}
</script>

<style lang="scss" scoped>
</style>
